/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.lieskove.jianghongtiao.paris.webclient.persistence;

import org.apache.log4j.Logger;
import sk.lieskove.jianghongtiao.common.utils.PropertiesUtils;
import sk.lieskove.jianghongtiao.common.web.UrlUtils;
import sk.lieskove.jianghongtiao.websearch.enums.DocumentType;
import sk.lieskove.jianghongtiao.websearch.document.preprocessing.SupportedLanguages;
import sk.lieskove.jianghongtiao.websearch.service.ExcludeReasonEnum;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.Transient;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Timestamp;

/**
 * 
 * @author xjuraj e-mail: jjurco.sk_gmail.com
 */
public class ClassificationItem implements Serializable {

    @Transient
    private transient Logger log = Logger.getLogger(ClassificationItem.class);
    @Transient
    private transient PropertiesUtils pu = new PropertiesUtils(ClassificationItem.class);
    private Long id;
    @Enumerated(EnumType.STRING)
    private DocumentType documentType;
    private Long searchResponseId;
    private Long wsdId;
    private String serviceName;
    private String uuid;
    @Lob
    private String url;
    private Integer searchPosition;
    private String title;
    @Lob
    private String description;
    private String proxyString;
    private String encoding;
    @Enumerated(EnumType.STRING)
    private SupportedLanguages languageName;
    private String mimeType;
    private Integer responseStatusCode;
    private String fileLocation;
    private String originalFileLocation;
    private Long fileSize;
    private Timestamp fetchTime;
    private String searchQuery;
    private Timestamp loadingTime;
    @Enumerated(EnumType.STRING)
    private ExcludeReasonEnum excludeReason;
    
    
    public String getTrimUrl(){
        try {
            return UrlUtils.trimUrl8(new URL(url));
        } catch (MalformedURLException ex) {
            log.error("URL '"+url+"' is not valid!");
        }
        return null;
    }


    public ClassificationItem() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DocumentType getDocumentType() {
        return documentType;
    }

    public void setDocumentType(DocumentType documentType) {
        this.documentType = documentType;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public ExcludeReasonEnum getExcludeReason() {
        return excludeReason;
    }

    public void setExcludeReason(ExcludeReasonEnum excludeReason) {
        this.excludeReason = excludeReason;
    }

    public Timestamp getFetchTime() {
        return fetchTime;
    }

    public void setFetchTime(Timestamp fetchTime) {
        this.fetchTime = fetchTime;
    }

    public String getFileLocation() {
        return fileLocation;
    }

    public void setFileLocation(String fileLocation) {
        this.fileLocation = fileLocation;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public SupportedLanguages getLanguageName() {
        return languageName;
    }

    public void setLanguageName(SupportedLanguages languageName) {
        this.languageName = languageName;
    }

    public Timestamp getLoadingTime() {
        return loadingTime;
    }

    public void setLoadingTime(Timestamp loadingTime) {
        this.loadingTime = loadingTime;
    }

    public Logger getLog() {
        return log;
    }

    public void setLog(Logger log) {
        this.log = log;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public String getOriginalFileLocation() {
        return originalFileLocation;
    }

    public void setOriginalFileLocation(String originalFileLocation) {
        this.originalFileLocation = originalFileLocation;
    }

    public String getProxyString() {
        return proxyString;
    }

    public void setProxyString(String proxyString) {
        this.proxyString = proxyString;
    }

    public PropertiesUtils getPu() {
        return pu;
    }

    public void setPu(PropertiesUtils pu) {
        this.pu = pu;
    }

    public Integer getResponseStatusCode() {
        return responseStatusCode;
    }

    public void setResponseStatusCode(Integer responseStatusCode) {
        this.responseStatusCode = responseStatusCode;
    }

    public Integer getSearchPosition() {
        return searchPosition;
    }

    public void setSearchPosition(Integer searchPosition) {
        this.searchPosition = searchPosition;
    }

    public String getSearchQuery() {
        return searchQuery;
    }

    public void setSearchQuery(String searchQuery) {
        this.searchQuery = searchQuery;
    }

    public Long getSearchResponseId() {
        return searchResponseId;
    }

    public void setSearchResponseId(Long searchResponseId) {
        this.searchResponseId = searchResponseId;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Long getWsdId() {
        return wsdId;
    }

    public void setWsdId(Long wsdId) {
        this.wsdId = wsdId;
    }
    
    @Override
    public String toString() {
        return "ClassificationItem{" + "log=" + log + ", pu=" + pu + ", csId=" + id + ", documentType=" + documentType + ", searchResponseId=" + searchResponseId + ", wsdId=" + wsdId + ", serviceName=" + serviceName + ", uuid=" + uuid + ", url=" + url + ", searchPosition=" + searchPosition + ", title=" + title + ", description=" + description + ", proxyString=" + proxyString + ", encoding=" + encoding + ", languageCode=" + languageName + ", mimeType=" + mimeType + ", responseStatusCode=" + responseStatusCode + ", fileLocation=" + fileLocation + ", originalFileLocation=" + originalFileLocation + ", fileSize=" + fileSize + ", fetchTime=" + fetchTime + ", searchQuery=" + searchQuery + ", loadingTime=" + loadingTime + ", excludeReason=" + excludeReason + '}';
    }
}
